# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 消费者.py
# @Author: dongguangwen
# @Date  : 2025-04-12 12:43
import pika


def callback(ch, method, properties, body):
    print(f"[📨] 收到消息：{body.decode()}")
    ch.basic_ack(delivery_tag=method.delivery_tag)


credentials = pika.PlainCredentials('admin', 'password')
connection = pika.BlockingConnection(
    pika.ConnectionParameters('192.168.1.119', credentials=credentials, virtual_host='my_vhost'))
channel = connection.channel()

# 再次声明（参数必须一致）
channel.queue_declare(queue='durable_queue', durable=True)

channel.basic_consume(queue='durable_queue', on_message_callback=callback)
print("[🔁] 等待消息中...")
channel.start_consuming()
